package com.xand.bt.terminal.ui.depth;

import java.awt.Component;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JTable;

import com.xand.bt.terminal.dispatcher.MarketDepthDispatcher;
import com.xand.bt.terminal.main.BitcoinTerminal;
import com.xand.bt.terminal.util.BitcoinTerminalConst;

public class MarketDepthTableMouseListener implements MouseListener {

	public void mouseClicked(MouseEvent event) {
		
		int count = event.getClickCount();
		if(count > 1) {
			
			Component component = event.getComponent();
			JTable myTable = (JTable)component;
			
			int row = myTable.rowAtPoint(event.getPoint());
			int column = myTable.columnAtPoint(event.getPoint());
			
			BitcoinTerminal terminal = BitcoinTerminal.getInstance();
			MarketDepthDispatcher dispatcher = terminal.getMarketDepthDispatcher();
			
			if(column == MarketDepthTableModel.COLUMN_ASK_PRICE) {
				
				dispatcher.marketDepthClicked(BitcoinTerminalConst.MARKET_LEVEL_DIRECTION_ASK, row);
				
			} else if(column == MarketDepthTableModel.COLUMN_BID_PRICE) {
				
				dispatcher.marketDepthClicked(BitcoinTerminalConst.MARKET_LEVEL_DIRECTION_BID, row);
				
			}
			
		}
		
	}

	public void mouseEntered(MouseEvent event) {
	}

	public void mouseExited(MouseEvent event) {
	}

	public void mousePressed(MouseEvent event) {
	}

	public void mouseReleased(MouseEvent event) {
	}

}
